package TcpDemon01;

import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

// 客户端
public class TcpClientDemon01 {
    public static void main(String[] args) throws UnknownHostException {
        // 1. 服务器的地址和端口号
        InetAddress serverIP=InetAddress.getByName("127.0.0.1");
        int port=9999;
        try(
                // 2. 创建socket连接
                Socket socket=new Socket(serverIP,port);
                // 3. 发送信息 IO流
                OutputStream os=socket.getOutputStream();
                ){
            os.write("你好，欢迎学习狂神说Java".getBytes());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
